//
//  ChoicesTableViewController.m
//  HongYanNews
//
//  Created by 123 on 14-7-5.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "ChoicesTableViewController.h"

@interface ChoicesTableViewController ()

@end

@implementation ChoicesTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.title = self.title;
    [self customLeftBarButtonItem];
    
    if (MAIN_VERSION >= 7) {
        self.tableView.separatorInset = UIEdgeInsetsMake(0, -10, 0, 0);
    }
    
    self.tableView.rowHeight = 48;
    
    // 隐藏tableview多余的分割线
    [self setExtraCellLineHidden:self.tableView];
}

// 自定义LeftBarButtonItem
- (void)customLeftBarButtonItem {
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 28)];
    [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = - 10;
    if (ios7) {
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,leftBarButtonItem];
    }else{
        self.navigationItem.leftBarButtonItems = @[leftBarButtonItem];
    }
}

// 隐藏tableview多余的分割线
-(void)setExtraCellLineHidden: (UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [_dataArr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.backgroundColor = [UIColor clearColor];
    
    cell.textLabel.text = _dataArr[indexPath.row];
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [self.choiceDelegate showChoice:cell.textLabel.text SelectedIndex:indexPath.row Tag:self.tag_];
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 返回
- (void)back {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
